//
//  AddPopView.m
//  IntelligentHousehold
//
//  Created by wmwMAC on 17/6/26.
//  Copyright © 2017年 Cassie. All rights reserved.
//

#import "AddPopView.h"

#import "WhiteListModle.h"

@interface AddPopView()
@property (nonatomic, strong) UITextField *tf;

@end
@implementation AddPopView



-(void)setTelStr:(NSString *)telStr{
    _telStr = telStr;
    if (_telStr.length) {
        _tf.text = _telStr;
    }
}
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addViewUI];
    }
    return self;
}
-(void)backBtnClick{
    [self removeFromSuperview];
}

-(void)addViewUI{
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    backBtn.frame = CGRectMake(0, 0, kUIScreenWidth, kUIScreenHeight);
    backBtn.backgroundColor = [UIColor blackColor];
    backBtn.alpha = 0.8;
    [backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:backBtn];
    
    
    CGFloat backV_Weidth = kUIScreenWidth-80;
    UIView *backView= [[UIView alloc] initWithFrame:CGRectMake(40, kUIScreenHeight/3, backV_Weidth, 155)];
    backView.backgroundColor = [UIColor whiteColor];
    backView.layer.cornerRadius = 10;
    backView.clipsToBounds = YES;
    [self addSubview:backView];
    
    CGFloat titleLable_height = 30;//+10
    CGFloat TF_height = 40; //+10
    CGFloat footBtn_height = 60;
    
    UILabel *lable = [MyUtil createLabelFrame:CGRectMake(20, 5, backV_Weidth-40, titleLable_height) title:@"提示" textColor:[UIColor blackColor] textAlignment:NSTextAlignmentCenter font:[UIFont systemFontOfSize:18]];
    [backView addSubview:lable];
    
    
    _tf = [MyUtil createTextFiledFrame:CGRectMake(10, titleLable_height+15, backV_Weidth-20, TF_height) placeHolder:@"请输入号码"];
    
    [backView addSubview:_tf];
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    leftBtn.frame = CGRectMake(0, titleLable_height+TF_height+25, backV_Weidth/2, footBtn_height);
    [leftBtn setTitle:@"取消" forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:leftBtn];
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    rightBtn.frame = CGRectMake(backV_Weidth/2, titleLable_height+TF_height+25, backV_Weidth/2, footBtn_height);
    [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setTitle:@"确定" forState:UIControlStateNormal];
    [backView addSubview:rightBtn];
    
    
    UIView *lineView1 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMinY(leftBtn.frame), backV_Weidth, 1)];
    lineView1.backgroundColor = BaseColor;
    [backView addSubview:lineView1];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(leftBtn.frame)-0.5, CGRectGetMinY(leftBtn.frame), 1, CGRectGetHeight(leftBtn.frame))];
    lineView.backgroundColor = BaseColor;
    [backView addSubview:lineView];
    
}

-(void)rightBtnClick{
    _telStr = _tf.text;
    
    BOOL istel = [BasePublicMethord isMobileNumber:_telStr];
    
    if (istel) {
        
//        BOOL canAdd = YES;
//        
//        if (self.type == 1) {//成员 可以重复添加
//            
//        }else{//管理员排重
////            for (WhiteListModle *modle in self.dataArr) {
////                if ([modle.wtell isEqualToString:_telStr]) {
////                    canAdd = NO;
////                }
////            }
//
//        }
//        15707903416
//        if (canAdd) {
            if ([self.delegate respondsToSelector:@selector(addPopViewPassTel:TelId:)]) {
                [self.delegate addPopViewPassTel:self.telStr TelId:self.telId];
            }
            [self removeFromSuperview];
//        }else{
//            [MBProgressHUD showText:@"已有此成员号码"];
//        }
        
    }else{
        [MBProgressHUD showText:@"请正确输入手机号码"];
    }

    

}










@end
